#ifndef STACK_H_INCLUDED
#define STACK_H_INCLUDED

//#define NDEBUG
#include <assert.h>

/*
    simple array stack
*/

template <class T>
class Stack{
private:
	unsigned int size;
	unsigned int arraySize;
	T* storage;
public:
    Stack(const unsigned int& arrayLength) {
		size=0;
		storage=new T[arrayLength];
		arraySize=arrayLength;
	};

	void push(const T& toPush) {
		if(size==arraySize)
			grow();
		storage[size]=toPush;
		++size;
	};

	void grow() {
		arraySize+=arraySize;
		T* temp = new T[arraySize];
		for(unsigned int i=size; i--;)
			temp[i]=storage[i];
		delete[] storage;
		storage = temp;
	};

	const T& pop() {
		assert(size!=0);
		return storage[--size];
	};

	const unsigned int& getSize() { return size; };

    ~Stack() {
		delete[] storage;
	};
};

#endif // STACK_H_INCLUDED
